package org.springframework.ai.mcp.samples.playwright;

import java.util.List;

import io.modelcontextprotocol.client.McpSyncClient;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.mcp.SyncMcpToolCallbackProvider;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class Application {

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}

	@Bean
	public CommandLineRunner chatbot(ChatClient.Builder chatClientBuilder, List<McpSyncClient> mcpSyncClients) {

		return args -> {

			var chatClient = chatClientBuilder
					.defaultSystem("You are a thoughtful assistant that breaks down complex tasks into steps.,** After planning, execute the steps using available tools.**")
					.defaultTools(new SyncMcpToolCallbackProvider(mcpSyncClients))
					.defaultAdvisors(new MessageChatMemoryAdvisor(new InMemoryChatMemory()))
					.build();

			String userInput = "通过bing搜索2个关于中国股市消息最权威的网站,并通过这2个网站获取今天中国股市的情况，分别总结2个网站关于中国股市的情况，最后输出总结报告";
			System.out.println("\nUSER: "+userInput);
			System.out.println("\nASSISTANT: " +
			chatClient.prompt(userInput) // Get the user input
					.call()
					.content());
		};
	}
}
